package cn.edu.bcu.ls.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.edu.bcu.ls.entity.History;
import cn.edu.bcu.ls.entity.Hot;
import cn.edu.bcu.ls.serviceImpl.HistoryService;
import io.swagger.annotations.ApiOperation;

@RestController
public class HistoryController {

	@Autowired
	private HistoryService historyService;
	
	/**
	 * 增加历史
	 * @param History
	 * @return
	 */
	@ApiOperation(value = "添加历史，传入你想要的传的值就行")
	@PostMapping(value="History")
	public boolean insertHistory(History history) {
		if (historyService.insertSelective(history) >0) {
			return true;
		}else {
			return false;
		}
	}
	
	 @ApiOperation(value = "删除历史，传入id")
	 @DeleteMapping(value="History/{h_id}")
	 public boolean deleteUser(@PathVariable("h_id") Integer h_id) {
		 if (historyService.deleteByPrimaryKey(h_id) >0 ) {
				return true;
			}else {
				return false;
			}
	 }
	 
	 @ApiOperation(value="修改历史信息，传入id和想修改的值")
	 @PutMapping(value="History")
	 public boolean updateTag(History history) {
		 if (historyService.updateByPrimaryKeySelective(history) >0) {
				return true;
			}else {
				return false;
			}
	 }
	 @ApiOperation(value="查看历史 传入id")
	 @GetMapping(value="History")
	 public List<History> queryHistory(History history) {
		 return historyService.selectByPrimaryKey(history);
		 
	 }
	 
	 @ApiOperation(value="查看課程熱度")
	 @GetMapping(value="Hot")
	 public List<Hot> getHotByCourse() {
		 return historyService.getHotByCourse();
		 
	 }
	
}
